import { Entity, Column, PrimaryGeneratedColumn, UpdateDateColumn, ManyToOne, JoinColumn } from 'typeorm';
import { ApiProperty} from '@nestjs/swagger';
import {
  IsOptional,
  IsString,
  MaxLength,
  MinLength,
  IsNotEmpty,
  IsEmail,
  IsPhoneNumber,
  IsDate,
  ValidateNested
} from "class-validator";
import { Goods } from './goods.entity';
import { Attribute } from './attribute.entity';

@Entity()
export class GoodsAttribute {
  @PrimaryGeneratedColumn()
  id: number;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'int', nullable: false})
  goods_id: number;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'int', nullable: false})
  attribute_id: number;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'text', nullable: false})
  value: string;

  @ManyToOne(type => Attribute, attribute => attribute.goodsAttribute)
  @JoinColumn({
    name:"attribute_id"
  })
  attribute: Attribute

  @ManyToOne(type => Goods, goods => goods.goodsAttribute)
  @JoinColumn({
    name:"goods_id"
  })
  goods: Goods
}
